import { Text } from "@tarojs/components";
import ByText, { ByTextProps } from "../ui/ByText";
import { isUndefined } from "@tarojs/shared";

export default ({
  prefix = "¥",
  suffix,
  value,

  ...rest
}: {
  prefix?: string;
  value?: number;
  suffix?: string;
} & ByTextProps) => {
  const isMinus = !!(value && value < 0);
  const valueText = isUndefined(value) ? value : Math.abs(value);

  return (
    <ByText {...rest}>
      {isMinus && "-"}
      <Text className="text-[0.8em] font-[400]">{prefix}</Text>
      {valueText?.toLocaleString()}
      {suffix}
    </ByText>
  );
};
